
library(readr)
library(DescTools)
study2 <- read_csv("study2.csv")

#Gender
study2$Male<-study2$Gender
study2$Male[study2$Gender==1]<-1
study2$Male[study2$Gender==2]<-0
study2$Male[study2$Gender==3]<-0

##education
study2$Education[study2$Education==1]<-0
study2$Education[study2$Education==2]<-0
study2$Education[study2$Education==3]<-1
study2$Education[study2$Education==4]<-1
study2$Education[study2$Education==5]<-2
study2$Education[study2$Education==6]<-2
study2$Education[study2$Education==7]<-2
study2$Education[study2$Education==8]<-2
study2$Education[study2$Education==9]<-2
study2$Education[study2$Education==10]<-NA
study2$Education[study2$Education==11]<-NA
#PID
study2$pid_final<-study2$PID
study2$pid_final[study2$pid_dem==1]<-0
study2$pid_final[study2$pid_dem==2]<-1
study2$pid_final[study2$pid_rep==2]<-5
study2$pid_final[study2$pid_rep==1]<-6
study2$pid_final[study2$pid_ind==1]<-4
study2$pid_final[study2$pid_ind==2]<-3
study2$pid_final[study2$pid_ind==3]<-2


##FF measure



#Code all Missing as 0
##control
study2$Q9[is.na(study2$Q9)]<-0
study2$Q10[is.na(study2$Q10)]<-0
study2$Q11[is.na(study2$Q11)]<-0
study2$Q15[is.na(study2$Q15)]<-0
##girl
study2$Q13[is.na(study2$Q13)]<-0
study2$Q14[is.na(study2$Q14)]<-0
study2$Q16[is.na(study2$Q16)]<-0
study2$Q17[is.na(study2$Q17)]<-0
##boy
study2$Q19[is.na(study2$Q19)]<-0
study2$Q20[is.na(study2$Q20)]<-0
study2$Q21[is.na(study2$Q21)]<-0
study2$Q22[is.na(study2$Q22)]<-0


study2$Independence<-as.numeric(study2$Q9)+as.numeric(study2$Q13)+as.numeric(study2$Q19)
study2$Obedience<-as.numeric(study2$Q10)+as.numeric(study2$Q14)+as.numeric(study2$Q20)
study2$Curiosity<-as.numeric(study2$Q11)+as.numeric(study2$Q16)+as.numeric(study2$Q21)
study2$Considerate<-as.numeric(study2$Q15)+as.numeric(study2$Q17)+as.numeric(study2$Q22)


study2$Independence[study2$Independence==0]<-NA
study2$Obedience[study2$Obedience==0]<-NA
study2$Curiosity[study2$Curiosity==0]<-NA
study2$Considerate[study2$Considerate==0]<-NA



#Approve
study2$Approve<-4-study2$Approve
#Vote
study2$Vote[study2$Vote==2]<-0
study2$Vote[study2$Vote==3]<-NA
study2$Vote[study2$Vote==4]<-NA

#LGBTmarry
study2$LGBTmarry[study2$LGBTmarry==4]<-2
study2$LGBTmarry[study2$LGBTmarry==6]<-3

#UseofForce
study2$uof<-5-study2$`Use of Force`

#Imports
study2$imports[study2$imports==2]<-0

#Border Wall
study2$wall<-3-study2$`Border wall`

#Guns
study2$guns<-3-study2$guns  


study2$treatment<-study2$FL_17_DO

table(study2$Obedience)

study2$auth <- (study2$Independence-1 + 2-study2$Obedience + 
                       study2$Curiosity-1 + study2$Considerate-1)

study2$treatment2<-as.numeric(as.factor(study2$FL_17_DO))
table(study2$treatment)
#rep.Control <- subset(study2, treatment2==2)
#rep.Girl <- subset(study2, treatment2==3)
#rep.Boy <- subset(study2, treatment2==1)

